home *** CD-ROM | disk | FTP | other *** search
- Path: mics.demon.co.uk!Bill
- From: Bill Michell <Bill@mics.demon.co.uk>
- Newsgroups: comp.lang.c++
- Subject: Re: MFC Appl. only containing a dialog
- Date: Wed, 17 Apr 1996 13:29:36 +0100
- Organization: None
- Distribution: world
- Message-ID: <w+4ArLAwQOdxEwwP@mics.demon.co.uk>
- References: <TBD2JR_3.96Apr11101925@pruef1.atlas.de> <316DC9D3.7FCD@panix.com>
- NNTP-Posting-Host: mics.demon.co.uk
- X-NNTP-Posting-Host: mics.demon.co.uk
- MIME-Version: 1.0
- X-Newsreader: Turnpike Version 1.12 <uiEOes1orVXTvvWgSAnAOBUy+p>
-
- In article <316DC9D3.7FCD@panix.com>, Alex Chacha <achacha@panix.com>
- writes
- >cae2/test/pruef1 Joerg Redenius wrote:
- >
- >> I want to write a very simple application using my MSVC++ 1.52.
- >> The application should only display a small dialog WITH help
- >> feature.
- >
- >This is relatively easy:
- >1. create an application using appwizard
- >2. using appstudio create a dialog you want to use
- >3. using classwizard create the class for your new dialog
- >4. remove the doc template in winapp and it's usage (mostly in
- >InitInstance)
- >5. remove view/doc/frame files from your project
- >6. delete them (so they don't clutter your sub-dir)
- >7. in InitInstance find the routine (m_pMainWnd = ...)
- >8. replace it with:
- > CMyDialog *dialogX = new CMyDialog;
- > m_pMainWnd = dialogX;
- >
- >(Don't remember if you need to call DoModal, but I think you do)
- >
- >9. for non modal dialogs you have to call CMyDialog::Create function,
- >but this is rare...
- >
- >Let me know how it went. I did this on several occasions with much
- >success...
- >
- There are a few extra things you will need to do if you want the dialog
- box to have a properly working minimise button. I got the code from a
- nic man from microsoft:
- From stephsm@microsoft.com Wed Jan 10 17:20:14 1996
-
- Below is the code snippet I mentioned. You need to provide
- functionality for the following three functions, as well as adding the
- m_hIcon member variable for
- your dialog class.
- The OnPaint function handles the drawing of the icon.
- The OnQueryDragIcon function handles the dragging of the icon around the
- screen
- by the user.
- The Constructor loads the icon, and passes the icon's handle into the
- m_hIcon
- member variable. Remember to provide an icon resource to pass to
- LoadIcon!
-
-
- If you have any more problems, don't hesitate to give us a call!
-
- Regards,
-
- Steve Smith, Microsoft Systems Developer Support.
-
-
- // If you add a minimize button to your dialog, you will need the code
- below
- // to draw the icon. For MFC applications using the document/view
- model,
- // this is automatically done for you by the framework.
-
- void CDemoDlg::OnPaint()
- {
- if (IsIconic()) // This member function returns TRUE if a window
- // is iconised. Otherwise (suprisingly) it
- returns FALSE.
- {
- CPaintDC dc(this); // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(),
- 0);
- // This message ensures the background behind where the
- // Icon is to be drawn is painted with the brush of the
- parent
- // window - or repaint the desktop in that area.
-
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- // The GetSystemMetrics function returns system
- information,
- // such as screen size (in pixels) and loads of other
- stuff.
- // This can be a useful function - have a look at the
- documentation
- // for it in the online help.
-
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- // Draw icon onto display context.
- }
- else
- {
- CDialog::OnPaint();
- // If you had your own OnPaint code for the dialog, you
- would
- // place that here.
- }
- }
-
- // The system calls this to obtain the cursor to display while the user
- drags
- // the minimized window. this is necessary if you want the user to be
- able to drag the
- // icon around the screen!
- HCURSOR CDemoDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- // Tells windows to use the icon as a cursor while the user is
- dragging.
- }
-
- CDemoDlg::CDemoDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CDemoDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDemoDlg)
- // NOTE: the ClassWizard will add member initialization
- here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon
- in Win32
- // But you will probably (!) need it for win16 - you would place
- the destroy
- // icon in the CDemoDlg::~CDemoDlg function.
-
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
-
-
-
- --
- Bill Michell eMail: Bill@mics.demon.co.uk
-